# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-regexp_parser
pkgver=2.6.0
pkgrel=1
pkgdesc='A library for tokenizing, lexing, and parsing Ruby regular expressions'
arch=(any)
url='https://github.com/ammar/regexp_parser'
license=(MIT)
depends=(ruby)
makedepends=(ragel ruby-rake ruby-rspec)
checkdepends=(ruby-ice_nine ruby-regexp_property_values ruby-benchmark-ips)
options=(!emptydirs)
source=(https://github.com/ammar/regexp_parser/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('6582ed51cd17d3d71ba8373f6803942e10674cb91f0e7724a49b21be61eea8b7')

prepare() {
  cd regexp_parser-$pkgver
  sed -i -e '/gouteur/d' -e '/rubocop/d' Gemfile
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd regexp_parser-$pkgver
  rake build
  gem build regexp_parser.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    regexp_parser-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd regexp_parser-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake spec
}

package() {
  cd regexp_parser-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
